using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Drawing;

namespace Dogfight2008.Common.Tests
{
  [TestFixture]
  public class ColoredTriangleSoupFixture
  {
    ColoredTriangleSoup cts;

    [SetUp]
    public void Init()
    {
      cts = ConstructSoup();
    }

    [Test]
    public void Construct() {
    }

    [Test]
    public void AddTriangle()
    {
      cts.Add(ColoredTriangleFixture.ConstructColoredTriangle());
    }

    [Test]
    public void AddTriangleCheckCount()
    {
      Assert.AreEqual(1, cts.TriangleCount);
    }

    public static ColoredTriangleSoup ConstructSoup()
    {
      ColoredTriangleSoup soup = new ColoredTriangleSoup();
      soup.Add(ColoredTriangleFixture.ConstructColoredTriangle());
      return soup;
    }

    [Test]
    public void AccessTriangle()
    {
      ColoredTriangle newTriangle = new ColoredTriangle(Color.Red, TriangleFixture.ConstructTriangle());
      cts.Add(newTriangle);
      Assert.AreEqual(newTriangle, cts[1]);
    }

    [Test]
    public void ReplaceTriangle()
    {
      ColoredTriangle newTriangle = new ColoredTriangle(Color.Red, TriangleFixture.ConstructTriangle());
      cts[0] = newTriangle;
      Assert.AreEqual(newTriangle, cts[0]);
    }

    [Test]
    public void Enumeration()
    {
      ColoredTriangle t1 = new ColoredTriangle(Color.Black, TriangleFixture.ConstructTriangle());
      ColoredTriangle t2 = new ColoredTriangle(Color.White, TriangleFixture.ConstructTriangle());
      ColoredTriangleSoup soup = new ColoredTriangleSoup();
      soup.Add(t1);
      soup.Add(t2);
      List<ColoredTriangle> expected = new List<ColoredTriangle>();
      expected.Add(t1);
      expected.Add(t2);
      List<ColoredTriangle> result = new List<ColoredTriangle>();
      foreach (ColoredTriangle tri in soup)
        result.Add(tri);
      CollectionAssert.AreEqual(expected, result);
    }

    [Test]
    public void Map()
    {
      ColoredTriangle t1 = new ColoredTriangle(Color.Black, TriangleFixture.ConstructTriangle());
      ColoredTriangle t2 = new ColoredTriangle(Color.White, TriangleFixture.ConstructTriangle());
      ColoredTriangleSoup soup = new ColoredTriangleSoup();
      soup.Add(t1);
      soup.Add(t2);
      soup.Map(delegate(ColoredTriangle triangle)
      {
        return new ColoredTriangle(Color.Yellow, triangle.Triangle);
      });
      List<ColoredTriangle> expected = new List<ColoredTriangle>();
      ColoredTriangle t1b = new ColoredTriangle(Color.Yellow, TriangleFixture.ConstructTriangle());
      ColoredTriangle t2b = new ColoredTriangle(Color.Yellow, TriangleFixture.ConstructTriangle());
      expected.Add(t1b);
      expected.Add(t2b);
      List<ColoredTriangle> result = new List<ColoredTriangle>();
      foreach (ColoredTriangle tri in soup)
        result.Add(tri);
      CollectionAssert.AreEqual(expected, result);
    }

    [Test]
    public void Equals()
    {
      ColoredTriangleSoup soup1 = ConstructSoup();
      ColoredTriangleSoup soup2 = ConstructSoup();
      Assert.AreEqual(soup1, soup2);
    }

    [Test]
    public void NotEquals()
    {
      ColoredTriangleSoup soup1 = ConstructSoup();
      ColoredTriangleSoup soup2 = ConstructSoup();
      soup2.Add(new ColoredTriangle(Color.Red, TriangleFixture.ConstructTriangle()));
      Assert.AreNotEqual(soup1, soup2);
    }
  }
}
